const defaultAvatarUrl = 'https://fks.yiquhz.com/gulu/3ec4c.jpg'

Component({
  properties: {
    showBtn: {
      type: Boolean,
      value: null
    },
    openId: {
      type: String,
      value: null
    }
  },
  data: {
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: wx.getStorageSync('wechatName') || '',
    },
    openId: '',
    hasUserInfo: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
  },
  methods: {
    onLoad() {
    },
    onInputChange(e: any) {
      const nickName = e.detail.value
      this.setData({
        "userInfo.nickName": nickName,
        hasUserInfo: nickName,
      })
      wx.setStorageSync('wechatName', nickName)
    },
    getUserProfile() {
      // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      wx.getUserProfile({
        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    },
    goBind() {
      wx.reLaunch({
        url: '/pages/index/index'
      })
    }
  },
})
